const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require("copy-webpack-plugin");
const webpack = require('webpack')

module.exports = {
    mode: 'none',
    entry: {
        index: path.resolve(process.cwd(), './src/index.js'),
        'preview/preview': path.resolve(process.cwd(), './src/preview/preview.js')
    },
    output: {
        filename: '[name].js',
        path: path.resolve(process.cwd(), 'dist'),
        libraryTarget: 'umd', // 支持AMD CJS ESM script导入等
    },
    module: {
        rules: [{
                test: /\.js$/,
                use: 'babel-loader'
            },
            {
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ],
            },
        ]
    },
    plugins: [
        new webpack.CleanPlugin(),
        new webpack.DllReferencePlugin({
            context: process.cwd(),
            manifest: require(path.join(process.cwd(), 'build/library/library.json')),
        }),
        new CopyPlugin({
            patterns: [{
                from: path.join(process.cwd(), 'build/library/library.dll.js'),
                to: ""
            }, ],
        }),

        new HtmlWebpackPlugin({
            template: path.resolve(process.cwd(), '/src/index.html'),
            filenam: '[name].html',
            chunks: ['index']
        }),
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, '/src/preview/preview.html'),
            filename: 'preview/preview.html',
            chunks: ['preview']
        }),
    ],
}